package com.cn.tous.common.security.config;

import org.springframework.context.annotation.Configuration;

/**
 * @author mengwei
 * @description ResourceServerAutoConfiguration
 * @createDate 2025/7/26 12:28
 */
@Configuration
public class ResourceServerAutoConfiguration {



    /**
     * 配置安全过滤链
     */
//    @Bean
//    public SecurityFilterChain resourceServerSecurityFilterChain(HttpSecurity httpSecurity) throws Exception {
//        httpSecurity.authorizeHttpRequests((authorize) ->
//                        authorize.requestMatchers("/public/**").permitAll()
//                        .anyRequest().authenticated()
//                )
//                .oauth2ResourceServer(oauth2 -> oauth2
//                        .jwt(jwt -> jwt
//                                .jwtAuthenticationConverter(jwtAuthenticationConverter())
//                        )
//                );
//
//        return httpSecurity.build();
//    }

    /**
     * JWT认证转换器，用于将JWT中的声明转换为权限
     */
//    @Bean
//    public JwtAuthenticationConverter jwtAuthenticationConverter() {
//        JwtGrantedAuthoritiesConverter grantedAuthoritiesConverter = new JwtGrantedAuthoritiesConverter();
//        // 设置权限在JWT中的声明名称
//        grantedAuthoritiesConverter.setAuthoritiesClaimName("scope");
//        // 设置权限前缀
//        grantedAuthoritiesConverter.setAuthorityPrefix("");
//
//        JwtAuthenticationConverter jwtAuthenticationConverter = new JwtAuthenticationConverter();
//        jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(grantedAuthoritiesConverter);
//        return jwtAuthenticationConverter;
//    }
}
